<template>
    <div id="qr-code-full-region"></div>
</template>

<script lang="ts" setup>
import { onMounted } from 'vue'

const props = withDefaults(defineProps<{
    qrbox: number
    fps: number
}>(),{
    qrbox: 250,
    fps: 10
})

const emit = defineEmits<{
  (e: 'scanResult', decodedText: any, decodedResult: any): void
}>()

onMounted(() => {
    const config = {
      fps: props.fps,
      qrbox: props.qrbox,
    };
    
    const html5QrcodeScanner = new Html5QrcodeScanner('qr-code-full-region', config);
    html5QrcodeScanner.render(onScanSuccess);
})

// 扫描成功
const onScanSuccess = (decodedText: any, decodedResult: any) => {
    emit('scanResult', decodedText, decodedResult);
}
</script>

<style scoped lang="scss">

</style>